<template>
  <div class="wrapper">
    <swiper :options="swiperOption"  v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" />
      </swiper-slide>
      <!-- Optional controls -->
      <!--轮播图下面的点-->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        // loop 使轮播图左右循环切换
        loop: true
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  //scoped是让下面各组件不能相互干扰样式
  //为了达到修改其他组件样式的目的 要使用三个》》》
  .wrapper >>> .swiper-pagination-bullet-active
    background: white
  .wrapper
    /*宽度自适应 1.需要overflow height必须为0 然后 padding-bottom百分比 */
    overflow: hidden
    width: 100%
    height: 0
    padding-bottom: 31.25%
    background:#eee
    .swiper-img
      width: 100%
</style>
